(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.popup.apEffectiveSettingViewController', apEffectiveSettingViewController);
	apEffectiveSettingViewController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig' , 'authService', 'ajaxServiceFactory', 'validatorConfig', 'apEffectiveSettingService'];
	function apEffectiveSettingViewController($scope, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, authService, ajaxServiceFactory, validatorConfig, apEffectiveSettingService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("apEffectiveSettingViewController"), ajaxService = ajaxServiceFactory.buildAjaxService({
			getApEffectiveSettingData : {
				url : 'do/cda/apCommunity/effectiveSetting',
				method : 'post'
			},
		});
		ctrl.dialogsModule = dialogsModule;
//		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.apEffectiveSetting = {};
		ctrl.formName = "apEffectiveSettingForm";
		
		ctrl.init = function() {
			// init int
//			apEffectiveSettingService.initProfInt($scope, ctrl);
//			apEffectiveSettingService.initProfCostOfFundInt($scope, ctrl);
			// init pastdue
			apEffectiveSettingService.initProfPastdue($scope, ctrl, layoutConfig);
			// init fee
			apEffectiveSettingService.initProfFee($scope, ctrl, layoutConfig);
			// init Settlement Instruction
			apEffectiveSettingService.initProfSetlinst($scope, ctrl, layoutConfig);
			//
			apEffectiveSettingService.initGeneral($scope, ctrl).then(function() {
				// init data
				var params = ctrl.dialogsModule.params.apCommunity;
				ajaxService.getApEffectiveSettingData(params).then(function(response) {
					var initApEffectiveSetting = response.data || {};
					initApEffectiveSetting.prodSubtypeExtProperty = ctrl.dialogsModule.params.prodSubtypeExtProperty;
					apEffectiveSettingService.initLayoutConfigAndModel($scope, ctrl, initApEffectiveSetting, layoutConfig);
				});
			});
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
	}
})(angular);
